home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / multlang.zip / MULTREG.PAS < prev    next >
Pascal/Delphi Source File  |  1996-04-27  |  11KB  |  327 lines

  1. unit MultReg;
  2.  
  3. interface
  4.  
  5. Uses MultLang, MDialogs, MButtons;
  6.  
  7. procedure Register;
  8.  
  9. implementation
  10.  
  11. Uses DsgnIntf, Classes, MulAbout, Forms, LangEdit, Messages, SysUtils, Tabs,
  12.      Menus, StdCtrls, ExtCtrls, MCombBox, CompColl, WinProcs;
  13.  
  14. Type
  15.   {Languages Property Editor}
  16.   TLangTextProperty = Class(TPropertyEditor)
  17.   Public
  18.     Procedure Edit; Override;
  19.     Function GetAttributes: TPropertyAttributes; Override;
  20.     Function GetValue:String; Override;
  21.   End;
  22.  
  23.   {Language file Property Editor}
  24.   TLangFileProperty = Class(TStringProperty)
  25.   Public
  26.     Procedure Edit; Override;
  27.     Function GetAttributes: TPropertyAttributes; Override;
  28.   End;
  29.  
  30.   {Default language Property Editor}
  31.   TDefaultLangProperty = Class(TStringProperty)
  32.   Public
  33.     Function GetAttributes: TPropertyAttributes; Override;
  34.     Procedure GetValues(Proc: TGetStrProc); Override;
  35.   End;
  36.  
  37.   {Language component editor}
  38.   TMultLangEditor = Class(TComponentEditor)
  39.   Public
  40.     Procedure ExecuteVerb(Index:Integer); Override;
  41.     Function GetVerbCount:Integer; Override;
  42.     Function GetVerb(Index:Integer):String; Override;
  43.   End;
  44.  
  45.   {AdoptOn Property Editor}
  46.   TAdoptOnProperty = Class(TComponentProperty)
  47.   Public
  48.     Procedure GetValues(Proc: TGetStrProc); Override;
  49.   End;
  50.  
  51.   {About Property Editor}
  52.   TAboutProperty = Class(TPropertyEditor)
  53.   Public
  54.     Procedure Edit; Override;
  55.     Function GetAttributes: TPropertyAttributes; Override;
  56.     Function GetValue:String; Override;
  57.   End;
  58.  
  59. Procedure TAboutProperty.Edit;
  60. {Invokes the about dialog when clicking on ... in Object Inspector}
  61. Begin
  62.   TMultLang(GetComponent(0)).ShowAbout;
  63. End;
  64.  
  65. Function TAboutProperty.GetAttributes: TPropertyAttributes;
  66. {Make settings for just displaying a string in the about property in the Object Inspector}
  67. Begin
  68.   GetAttributes := [paDialog, paReadOnly];
  69. End;
  70.  
  71. Function TAboutProperty.GetValue: String;
  72. {Text in the ObjectInspector for the About property}
  73. Begin
  74.   GetValue := '(Dbl click here ...)';
  75. End;
  76.  
  77. Type
  78. TComponentCollectorEditor = class(TComponentEditor)
  79. public
  80.   procedure Edit; override;
  81.   procedure ExecuteVerb(Index:Integer); override;
  82.   function GetVerbCount:Integer; override;
  83.   function GetVerb(Index:Integer):string; override;
  84. end;
  85.  
  86. TAboutProperty2 = class(TPropertyEditor)
  87. public
  88.   procedure Edit; override;
  89.   function GetAttributes: TPropertyAttributes; override;
  90.   function GetValue:string; override;
  91. end;
  92.  
  93. TUpdateProperty = class(TPropertyEditor)
  94. public
  95.   procedure Edit; override;
  96.   function GetAttributes: TPropertyAttributes; override;
  97.   function GetValue:string; override;
  98. end;
  99.  
  100. procedure TAboutProperty2.Edit;
  101. {Invokes the about dialog when clicking on ... in Object Inspector}
  102. begin
  103.   TComponentCollector(GetComponent(0)).ShowAbout;
  104. end;
  105.  
  106. function TAboutProperty2.GetAttributes: TPropertyAttributes;
  107. {Make settings for just displaying a string in the about property in the Object Inspector}
  108. begin
  109.   GetAttributes := [paDialog, paReadOnly];
  110. end;
  111.  
  112. function TAboutProperty2.GetValue: String;
  113. {Text in the ObjectInspector for the About property}
  114. begin
  115.   GetValue := '(About)';
  116. end;
  117.  
  118. procedure TUpdateProperty.Edit;
  119. {Invokes the about dialog when clicking on ... in Object Inspector}
  120. begin
  121.   TComponentCollector(GetComponent(0)).Collect;
  122. end;
  123.  
  124. function TUpdateProperty.GetAttributes: TPropertyAttributes;
  125. {Make settings for just displaying a string in the about property in the Object Inspector}
  126. begin
  127.   GetAttributes := [paDialog, paReadOnly];
  128. end;
  129.  
  130. function TUpdateProperty.GetValue: String;
  131. {Text in the ObjectInspector for the About property}
  132. begin
  133.   GetValue := '(Updates ...)';
  134. end;
  135.  
  136.  
  137. Procedure Register;
  138. {Register the component to the component palette and all Property Editors}
  139. Begin
  140.   RegisterPropertyEditor(TypeInfo(String), TMultLang, 'About', TAboutProperty);
  141.   RegisterPropertyEditor(TypeInfo(TList), TMultLang, 'Languages', TLangTextProperty);
  142.   RegisterPropertyEditor(TypeInfo(String), TMultLang, 'LanguageFile', TLangFileProperty);
  143.   RegisterPropertyEditor(TypeInfo(String), TMultLang, 'DefaultLanguage', TDefaultLangProperty);
  144.   RegisterPropertyEditor(TypeInfo(TComponent), TMultLang, 'AdoptOn', TAdoptOnProperty);
  145.   RegisterPropertyEditor(TypeInfo(String), TComponentCollector, 'About', TAboutProperty2);
  146.   RegisterPropertyEditor(TypeInfo(TStrings), TComponentCollector, 'OwnedComponents', TUpdateProperty);
  147.   RegisterComponents('Multi Lingual', [TMultLang, TMOpenDialog, TMSaveDialog, TMPrintDialog,
  148.      TMPrinterSetupDialog, TMFindDialog, TMReplaceDialog, TMFontDialog, TMColorDialog,
  149.      TMButtons, TMComboBox, TComponentCollector]);
  150.   RegisterComponentEditor(TMultLang, TMultLangEditor);
  151.   RegisterComponentEditor(TComponentCollector, TComponentCollectorEditor);
  152. End;
  153.  
  154. Procedure TMultLangEditor.ExecuteVerb(Index:Integer);
  155. {When right click on the component at design-time}
  156. Var OrgHlpFile:String;
  157. Begin
  158.   Case Index Of
  159.     0 : TMultLang(Component).ShowAbout;
  160.     1 : Begin
  161.         OrgHlpFile:=Application.HelpFile;
  162.         Application.HelpFile:='MULTLANG.HLP';
  163.         Application.HelpContext(10);
  164.         Application.HelpFile:=OrgHlpFile;
  165.         End;
  166.     2 : TMultLang(Component).Edit(Nil);
  167.   End;
  168. End;
  169.  
  170. Function TMultLangEditor.GetVerb(Index:Integer):String;
  171. {Right Click contents in design-time}
  172. Begin
  173.   Case Index Of
  174.     0 : GetVerb:='About ...'; {This is default to dbl-click}
  175.     1 : GetVerb:='Help Contents';
  176.     2 : GetVerb:='Edit Languages';
  177.   End;
  178. End;
  179.  
  180. Function TMultLangEditor.GetVerbCount:Integer;
  181. {Nr of items in Right Click popup at desing-time}
  182. Begin
  183.   GetVerbCount:=3;
  184. End;
  185.  
  186. Procedure TLangTextProperty.Edit;
  187. {When clicking on ... in Object Inspector}
  188. Begin
  189.   TMultLang(GetComponent(0)).Edit(Nil);
  190. End;
  191.  
  192. Function TLangTextProperty.GetAttributes: TPropertyAttributes;
  193. {Makes the property equal as TStrings}
  194. Begin
  195.   GetAttributes := [paDialog, paReadOnly];
  196. End;
  197.  
  198. Function TLangTextProperty.GetValue:String;
  199. {The name of Languages property in the Object Inspector}
  200. Begin
  201.   GetValue := '(Languages ...)';
  202. End;
  203.  
  204. Function TLangFileProperty.GetAttributes: TPropertyAttributes;
  205. {LanguageFile property, makes it possible to also bring up the Open dialog}
  206. Begin
  207.   GetAttributes := [paDialog];
  208. End;
  209.  
  210. Procedure TLangFileProperty.Edit;
  211. {Open selected in the LanguageFile property}
  212. Var LangEditForm:TLangEditorForm;
  213. Begin
  214.   LangEditForm:=TLangEditorForm.Create(Nil);
  215.   Try
  216.     LangEditForm.MOpenDialog1.Filter:=LangEditForm.MultLang1.GetString('LoadBtn_Filter');
  217.     LangEditForm.MOpenDialog1.Title:=LangEditForm.MultLang1.GetString('LoadBtn_Title');
  218.     LangEditForm.MOpenDialog1.DefaultExt:='LAN';
  219.     LangEditForm.MOpenDialog1.FileName:=GetStrValue;
  220.     If (LangEditForm.MOpenDialog1.Execute) Then
  221.       If (AnsiUpperCase(GetStrValue)<>AnsiUpperCase(LangEditForm.MOpenDialog1.FileName)) Then
  222.         {TMultLang(GetComponent(0)).SetLanguageFile(LangEditForm.MOpenDialog1.FileName);}
  223.         SetStrValue(LangEditForm.MOpenDialog1.FileName);
  224.   Finally
  225.     LangEditForm.Free;
  226.   End;
  227. End;
  228.  
  229. Function TDefaultLangProperty.GetAttributes: TPropertyAttributes;
  230. {Make settings for a drop down list of available languages}
  231. Begin
  232.   GetAttributes := [paValueList, paReadOnly];
  233. End;
  234.  
  235. Procedure TDefaultLangProperty.GetValues(Proc:TGetStrProc);
  236. {Returns the names of the available languages}
  237. Var Index:Integer;
  238. Begin
  239.  For Index:=0 To TMultLang(GetComponent(0)).Languages.Count-1 Do
  240.   If (PLangText(TMultLang(GetComponent(0)).Languages.Items[Index])^.Kind=rkLanguage) Then
  241.     Proc(StrPas(PLangText(TMultLang(GetComponent(0)).Languages.Items[Index])^.Value));
  242. End;
  243.  
  244. Procedure TAdoptOnProperty.GetValues(Proc:TGetStrProc);
  245. {Returns the names of the available AdoptOn controls}
  246. Var Index:Integer;
  247. Begin
  248.   With Designer.Form Do
  249.     For Index:=0 To ComponentCount-1 Do
  250.       If (Components[Index] is TTabSet) Or (Components[Index] is TMainMenu) Or
  251.          (Components[Index] is TPopupMenu) Or (Components[Index] is TListBox) Or
  252.          (Components[Index] is TComboBox) Or (Components[Index] is TRadioGroup) Or
  253.          (Components[Index] is TMe